package com.bbdjt.weixin.base.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.bbdjt.weixin.model.Doctor;
import com.github.pagehelper.PageInfo;

public abstract class BaseAction
{

	
	public String errorJson = "{\"msg\":\"失败\",\"type\":-1}";

	public String writeOK(Object obj) {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 200);
		m.put("msg", "成功");
		m.put("content", null == obj ? "" : obj);
		return JSON.toJSONString(m, SerializerFeature.WriteDateUseDateFormat);
	}
	
	public String writeOK() {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 200);
		m.put("msg", "成功");
		m.put("content","");
		return JSON.toJSONString(m);
	}
	
	public String lackError() {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 201);
		m.put("msg", "缺少参数");
		m.put("content", "");
		return JSON.toJSONString(m);
	}
	
	public String lackError(String msg) {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 201);
		m.put("msg", msg);
		m.put("content", "");
		return JSON.toJSONString(m);
	}
	
	public String error(Integer num ,String msg) {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", num);
		m.put("msg", msg);
		m.put("content", "");
		return JSON.toJSONString(m);
	}
	
	public String serviceError() {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 202);
		m.put("msg", "服务器异常");
		m.put("content", "");
		return JSON.toJSONString(m);
	}
	

	public String toLigerUiSelectJson(PageInfo pi) {
		return "{\"Rows\":" + (JSON.toJSONString(null == pi.getList() ? "" : pi.getList(), SerializerFeature.WriteDateUseDateFormat).toString())
				+ ",\"Total\":" + pi.getTotal() + "}";
	}

	public String toLigerUiSelectJson(List<?> list) {
		return "{\"Rows\":" + (JSON.toJSONString(null == list ? "" : list, SerializerFeature.WriteDateUseDateFormat).toString()) + ",\"Total\":"
				+ (null == list ? 0 : list.size()) + "}";
	}

	public String getAndroidDpi(String displayWidth, String displayHeigh, String displayDpi) {
		return "displayWidth=" + displayWidth + "&displayHeigh=" + displayHeigh + "&displayDpi=" + displayDpi;
	}
	
	public static void main(String[] args) {
		Doctor user = new Doctor();
		user.setId(1);
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("type", 200);
		m.put("msg", "成功");
		m.put("content", user);
		System.out.println(JSON.toJSONString(m));
		System.out.println(JSON.toJSONString(m, SerializerFeature.WriteDateUseDateFormat));
	}
}


















